/**
 * 序号列宽度自适应
 * @param gridId jqgridID
 */
function autoRNWidth(gridId){
	var page = $("#"+gridId).jqGrid('getGridParam','page');
    var rows = $('#'+gridId).getGridParam("rowNum");
    var maxnum = (rows*page).toString();
    var len = (maxnum.length)*10;
    $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
    $('#'+gridId+'_rn').css('width',len+'px');
}
/**
 * 当数据只有一条时默认选中
 * @param gridId
 */
function selectByOneData(gridId){
	var num = $("#"+gridId).jqGrid('getGridParam', 'records');
    if (num == 1){
    	var ids = jQuery("#"+gridId).jqGrid('getDataIDs');
    	$("#jqg_"+gridId+"_"+ids[0]).attr('checked',true);
    	$("#"+gridId).jqGrid('setSelection',ids[0]);
    }
}


function getGridColumValue(gridId,columName){
	var rowIds = $("#"+gridId).jqGrid('getGridParam', 'selarrrow');
	if (rowIds.length < 1){
		return "";
	}
	var str = "";
	for (var i = 0;i < rowIds.length; i++){
		var rowdata = $("#"+gridId).jqGrid('getRowData', rowIds[i]);
		str += rowdata[columName]+",";
    }
	if (str != ""){
		str = str.substring(0,str.length-1)
	}
	return str;
}

function batchSwitchStatus(gridId, nameColum, statusColum, status, info){
		var rowIds = $("#"+gridId).jqGrid('getGridParam', 'selarrrow');
		if (rowIds.length < 1){
			top.$.HN.message.alert("请选择要"+status+"的" + info, "","warn");
			return;
		}
		var str = "";
		var names = "";
		var infos = new Array();
		var j=0;
		for (var i = 0; i < rowIds.length; i++) {
			
			var rowdata = $("#"+gridId).jqGrid('getRowData', rowIds[i]);
			var temp = rowdata[statusColum].replace(/<.*?>/ig,"");
			if (status != temp){
				if(j<3){
					names += rowdata[nameColum]+"<br/>";
					if(j==2){
						names += "...";
					}
				}
				str += rowIds[i]+",";
				j++;
			}
	    }
		if (names != ""){
			names = names.substring(0,names.length-1);
			str = str.substring(0,str.length-1)
		} else {
			top.$.HN.message.alert("您选择的" + info + "已经是" + status + "状态","", "warn");
	    	return;
		}
		infos[0] = str;
		infos[1] = names;
		return infos;
	}
	